package com.ehotting.mqbd.zw.api.domain.netty;

import com.ehotting.eaf.core.utils.ByteUtils;
import com.ehotting.mqbd.zw.api.constants.ActionConstants;
import com.ehotting.mqbd.zw.api.domain.protoc.ZwFileDataTransfer;
import com.google.protobuf.InvalidProtocolBufferException;

public class FileSendReq extends ZwCommPacket {

    private ZwFileDataTransfer.ZwFileList zwFileList;

    private ZwFileDataTransfer.ZwFileSection zwFileSection;

    public FileSendReq() {
        super(ActionConstants.Cmd_FileSendStr);
    }

    @Override
    public void convertToHexStr() {
        if (zwFileList!=null && zwFileSection!=null) {
            byte[] zwFileListBuff = zwFileList.toByteArray();
            byte[] zwFileSectionBuff = zwFileSection.toByteArray();
            byte[] buff = ByteUtils.byteMerger(zwFileListBuff, zwFileSectionBuff);
            this.setBuff(buff);
        }
    }

    @Override
    public void convertToProp() {
        byte[] buff = this.getBuff();
        int bufSize = this.getHead().getBufSize();
        if (buff==null||bufSize==0){
            return;
        }
        try {
            this.zwFileList = ZwFileDataTransfer.ZwFileList.parseFrom(buff);
            this.zwFileSection = ZwFileDataTransfer.ZwFileSection.parseFrom(buff);
        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        FileSendReq req = new FileSendReq();
        System.out.println(req.toString());

    }
}
